package com.itheima.service;

import com.github.pagehelper.PageHelper;
import com.itheima.domain.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class StudentServiceTest {
    //查询全部
    @Test
    public void findAll() {
        //1.获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //2.获取mapper的代理对象
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //3.调用代理对象方法
        List<Student> list = mapper.findAll();


        for (Student student : list) {
            System.out.println(student);
        }
        sqlSession.close();
    }


    @Test
    public void Insert() {
        //1.获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //2.获取mapper的代理对象
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //3.调用代理对象方法
        Student stu = new Student(8, "刘诗诗", 23,1);
        Integer insert = mapper.insert(stu);
        System.out.println(insert);
        sqlSession.close();
    }
    @Test
    public void update() {
        //1.获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //2.获取mapper的代理对象
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //3.调用代理对象方法
        Student stu = new Student(8, "刘诗诗", 23,2);
        Integer insert = mapper.update(stu);
        System.out.println(insert);
        sqlSession.close();
    }
    @Test
    public void delete() {
        //1.获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //2.获取mapper的代理对象
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //3.调用代理对象方法

        Integer insert = mapper.delete(5);
        System.out.println(insert);
        sqlSession.close();
    }





}
